package com.xdf.xzymanagementsystem.controller;

import com.xdf.xzymanagementsystem.entity.ResponseResult;
import com.xdf.xzymanagementsystem.util.DatetimeUtils;
import com.xdf.xzymanagementsystem.util.JsonResult;
import com.xdf.xzymanagementsystem.util.ShiroUtils;
import com.xdf.xzymanagementsystem.util.SystemUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

/**
 * @author chanchaw
 * @create 2022-11-19 8:52
 */
@CrossOrigin
@RestController
@RequestMapping("/system")
public class SystemController {

    @Autowired
    private ShiroUtils shiroUtils;

    @PostMapping("/checkBillDate")
    public ResponseResult<Boolean> checkBillDate(@RequestBody Map<String,String> params) throws Exception {
        Date billDate = DatetimeUtils.parseDate(params.get("billDate"),"yyyy-MM-dd");
        return ResponseResult.<Boolean>builder().data(SystemUtils.checkBillDate(billDate)).build();
    }

    @GetMapping("/user")
    public JsonResult getSysUser(){
        return JsonResult.ok(shiroUtils.getCurrentUser());
    }
}
